package com.tbycoder.tby.utils;


import com.tbycoder.tby.entity.IposLogin;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class TokenUtil {
    public static String getUserId() {
        IposLogin loginUser = (IposLogin) getRequest().getAttribute(CommonConstant.LOGIN_USER);
        return loginUser.getUserId();
    }

    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return requestAttributes == null ? null : requestAttributes.getRequest();
    }
    public static String getIdentityId() {
        IposLogin loginUser = (IposLogin) getRequest().getAttribute(CommonConstant.LOGIN_USER);
        return String.valueOf(loginUser.getIdentityId());
    }

}
